package com.iwic.smartkidsdaycares;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;

import com.iwic.smartkidsdaycares.JazzyViewPager.TransitionEffect;

public class MainActivity extends FragmentActivity {
	JazzyViewPager mJazzy;
	SectionsPagerAdapter pagerAdapter;
	public static FragmentManager fragmentManager;
	private static String[] titles = new String[]
			{"Tumbuh Kembang Anak","Telpon Dokter","Rumah Sakit Terdekat",
		"Aktivitas Harian","Cerita Anak","Monitor Kamera","Referensi","Bantuan"};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		fragmentManager = getSupportFragmentManager();
		mJazzy = (JazzyViewPager)findViewById(R.id.jazzy_pager);
		pagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
		//mJazzy.setAdapter(pagerAdapter);
		//TransitionEffect effect = TransitionEffect.valueOf("CubeOut");
		mJazzy.setTransitionEffect(TransitionEffect.CubeOut);
		mJazzy.setAdapter(pagerAdapter);
		mJazzy.setPageMargin(30);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		return super.onOptionsItemSelected(item);
	}
	
	public class SectionsPagerAdapter extends FragmentPagerAdapter {

		public SectionsPagerAdapter(FragmentManager fm) {
			super(fm);
		}
		@Override
		public Object instantiateItem(ViewGroup container, final int position) {
		    Object obj = super.instantiateItem(container, position);
		    mJazzy.setObjectForPosition(obj, position);
		    return obj;
		}
		@Override
		public Fragment getItem(int position) {
			// getItem is called to instantiate the fragment for the given page.
			// Return a PlaceholderFragment (defined as a static inner class
			// below).
			Fragment fragment= null;
			if (position==0){
				fragment = new GrowthFragment();
				 
			} else if (position==1){ 
				fragment = new CallDoctor();
			} else if (position==2){ 
				fragment = new HospitalFragment();
				
			} else if (position==3){
				fragment = new DailyActivityFragment();
				 
			} else if (position==4){
				fragment = new StoryTellingFragment();
			} else if (position==5){
				fragment = new RealTimeMonitor();
			} else if (position==6){
				fragment = new ReferenceFragment();
			} else {	
				fragment = new HelpFragment();
				
			}
			return fragment;
		}

		@Override
		public int getCount() {
			// Show 3 total pages.
			return 7;
		}

		@Override
		public CharSequence getPageTitle(int position) {
			
			setTitle(titles[position]);
			return null;
		}
	}
}
